package com.example.crm.controller.customer;


import com.example.crm.entity.Customer;
import com.example.crm.service.CustomerService;
import com.example.crm.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/addCustomer")
public class AddCustomerController extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Customer customer = new Customer();
        customer.setCust_name(req.getParameter("cust_name"));
        customer.setCust_level(req.getParameter("cust_level"));
        customer.setCust_source(req.getParameter("cust_source"));
        customer.setCust_linkman(req.getParameter("cust_linkman"));
        customer.setCust_phone(req.getParameter("cust_phone"));
        customer.setCust_mobile(req.getParameter("cust_mobile"));
        System.out.println(customer);
        CustomerService customerService = new CustomerServiceImpl();

        try {
            customerService.addCustomer(customer);
            System.out.println("添加成功");
        } catch (SQLException troubles) {
            troubles.printStackTrace();
        }

    }
}
